package com.test.utils;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** Description: Author:
 * Heller (HellerSong@outlook.com) CreationTime: Jul 8, 2015 ** ** ** ** ** **
 * ** ** ** ** ** ** ** ** ** ** **
 **/
public class WebDriverUtility {
	private static WebDriver myDriver;
	private static WebDriverWait myWait;
	private static JavascriptExecutor myJsExecutor;
	private static Actions myActions;
	private static int timeout = 120;

	public static void initializeWebDriver(int browserTypeIndex) {
		BrowserType browserType = BrowserType.values()[browserTypeIndex];
		switch (browserType) {
		case BROWSER_IE:
			// First end related EXE process
			myDriver = new InternetExplorerDriver();
			break;

		case BROWSER_FIREFOX:
			// First end related EXE process
			break;

		case BROWSER_CHROME:
			// First end related EXE process
			break;

		case BROWSER_OPERA:
			// First end related EXE process
			break;

		default:
			myDriver = new InternetExplorerDriver();
			break;
		}
	}

	public static WebDriver getWebDriver() {
		return myDriver;
	}

	public static WebDriverWait getWait() {
		if (myDriver != null) {
			if (myWait == null) {
				myWait = new WebDriverWait(myDriver, timeout);
			}
			return myWait;
		} else {
			return null;
		}
	}

	public static JavascriptExecutor getJsExecutor() {
		if (myDriver != null) {
			if (myJsExecutor == null) {
				myJsExecutor = (JavascriptExecutor) myDriver;
			}
			return myJsExecutor;
		} else {
			return null;
		}
	}

	public static Actions getAction() {
		if (myDriver != null) {
			if (myActions == null) {
				myActions = new Actions(myDriver);
			}
			return myActions;
		} else {
			return null;
		}
	}

}
